﻿/*======================================
作者：洞庭夕照
创建：2017.8.26
网站：www.ninesky.cn
      mzwhj.cnblogs.com
代码：git.oschina.net/ninesky/Ninesky
版本：v1.0.0.0
======================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Ninesky.Models;
using Ninesky.IService;

namespace Ninesky.Web.Controllers.Manage
{
    /// <summary>
    /// 后台栏目控制器
    /// </summary>
    [Area("Manage")]
    public class CategoryController : Controller
    {
        private ICategoryService _categoryService;
        public CategoryController(ICategoryService categoryService)
        {
            _categoryService = categoryService;
        }
        
        /// <summary>
        /// 查找父栏目列表
        /// </summary>
        /// <returns>父栏目列表的json类型</returns>
        public async Task<IActionResult> GetParentCategoryList()
        {
            var categories =  await _categoryService.FindListAsync<int>(0, c => c.Type == CategoryType.General, c => c.CategoryId, true);
            return Json(categories.ToList());
        }

        /// <summary>
        /// 查找所有栏目
        /// </summary>
        /// <returns>栏目列表</returns>
        public async Task<IActionResult> GetCategoryList()
        {
            var categories = await _categoryService.FindAllAsync();
            return Json(categories.ToList());
        }
    }
}
